<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h1>用户注册</h1>
<form action="">
    <input type="text" name="username" placeholder="用户名"  @blur="check(username)">{{info}}<br>
    <input type="text" name="password" placeholder="密码"><br>
    <input type="text" name="nick" placeholder="昵称"><br>
    <input type="button" @click="reg()" value="注册">
</form>
<script src="js/axios.min.js"></script>
<script src="js/vue.min.js"></script>
<script>
    let v = new Vue({
        el:"form",
        data:{
            user:{
                username:"",
                password:"",
                nick:""
            },
            info:"111"
        },
        methods:{
            check(username){
                axios.get("/check?username="+username).then(function (response) {
                    v.info = response.data;
                })
            },
            reg(){
                axios.post("/reg",v.user).then(function (response) {
                    if (response.data==1){
                        alert("注册成功");
                        location.href="/login.html";
                    }else{
                        alert("用户名重复");
                    }

                })
            }
        }
    })
</script>
</body>
</html>